/**
 * 新增非平台材料消耗收货详情
 * 胡琼
 * 2017/8/21
 **/
var testConfig = require('../testConfig');
const ipcRenderer = require('electron').ipcRenderer;
var l = parseInt(window.sessionStorage.getItem("runTimes"));
var planData = JSON.parse(window.sessionStorage.getItem('planData'));
var caseData =  planData.cases[l];
var msg = {
  reportId:planData.reportId,
  taskId:planData.taskId,
  caseId:caseData.caseId,
  caseNumber:caseData.caseNumber,
  isOver:'false'
};
function TestProject() {
  this.init = function () {
    var arr = [];
    arr.push(this.step1,
      this.step2,
      this.step3,
      this.step4,
      this.step5,
      this.step6,
      this.step7,
      this.step8,
      this.step9,
      this.step10,
      this.step11,
      this.step12,
      this.step13);
    testConfig.testFun.runStep(arr);
  };
  this.step1 = function () {
    $("#aside-nav").find("div.coords").eq(2).find("a")[0].click();
    msg.stepResult = {
      byname:"skipProInfo",
      realData:$("#contentIframe iframe").attr('src')
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step2 = function () {
    $("#collapse3").find("li:nth-child(2) .second_lv_li")[0].click();
    msg.stepResult = {
      byname:"skipSiteDataManage",
      realData:$("#contentIframe iframe").attr('src')
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step3 = function () {
    testConfig.testFun.ai().find("input[data-name='projectCode']").val('PC99254EUK98');
    testConfig.testFun.ai().find("#search")[0].click();
    testConfig.testFun.ai().find("tr[data-index='0'] td")[0].click();
    msg.stepResult = {
      byname:"skipWorkerAttend",
      realData:testConfig.testFun.bi().find("#layui-layer-iframe1").attr('src')
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step4 = function () {
    testConfig.testFun.bi().find(".manage li:nth-child(2)")[0].click();
    msg.stepResult = {
      byname:"skipPlatformMater",
      realData:testConfig.testFun.bi().find("#layui-layer-iframe1").attr('src')
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step5 = function () {
    testConfig.testFun.bi().find(".materiel-one li:nth-child(2)")[0].click();
    msg.stepResult = {
      byname:"skipNoPlatformMater",
      realData:testConfig.testFun.bi().find("#layui-layer-iframe1").attr('src')
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step6 = function () {
    testConfig.testFun.bi().find("#add_m")[0].click();
    msg.stepResult = {
      byname:"addDeliverDetailPop",
      realData:testConfig.testFun.bi().find("#layer_addform1")
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step7 = function () {
    testConfig.testFun.bi().find("#id-category-1")[0].click();
    testConfig.testFun.bi().find(".dep-1 li:nth-child(1)").click();
    testConfig.testFun.bi().find(".dep-2 li:nth-child(1)").click();
    testConfig.testFun.bi().find(".dep-3 li:nth-child(22)").click();
    msg.stepResult = {
      byname:"breed",
      realData:testConfig.testFun.bi().find("#id-category-1 input[data-name='1758']").val()
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step8 = function () {
    testConfig.testFun.bi().find("#form1 input[data-name='receptionAt']").focus();
    testConfig.testFun.bi().find(".today")[0].click();
    msg.stepResult = {
      byname:"receptionAt",
      realData:testConfig.testFun.bi().find("input[data-name='receptionAt']").val()
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step9 = function () {
    testConfig.testFun.bi().find("#form1 input[data-name='attribute']")[0].focus();
    testConfig.testFun.bi().find("#form1 input[data-name='attribute']").val('吨');
    testConfig.testFun.bi().find("#form1 input[data-name='attribute']")[0].blur();
    msg.stepResult = {
      byname:"attribute",
      realData:testConfig.testFun.bi().find("input[data-name='attribute']").val()
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step10 = function () {
    testConfig.testFun.bi().find("#form1 input[data-name='quantity']")[0].focus();
    testConfig.testFun.bi().find("#form1 input[data-name='quantity']").val('2');
    testConfig.testFun.bi().find("#form1 input[data-name='quantity']")[0].blur();
    msg.stepResult = {
      byname:"quantity",
      realData:testConfig.testFun.bi().find("input[data-name='quantity']").val()
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step11 = function () {
    testConfig.testFun.bi().find("#form1 .layer-save")[0].click();
    msg.stepResult = {
      byname:"hold",
      realData:testConfig.testFun.bi().find("#layui-layer-iframe1").attr('src')
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step12 = function () {
    testConfig.testFun.bi().find("#id-materiel-category")[0].click();
    testConfig.testFun.bi().find(".dep-1 li:nth-child(1)").click();
    testConfig.testFun.bi().find(".dep-2 li:nth-child(1)").click();
    testConfig.testFun.bi().find(".dep-3 li:nth-child(22)").click();
    msg.stepResult = {
      byname:"selectBreed",
      realData:testConfig.testFun.bi().find("#id-materiel-category input[data-name='1758']").val()
    };
    ipcRenderer.sendToHost(JSON.stringify(msg));
  };
  this.step13 = function(){
    var address = window.location.href;
    var r = parseInt(window.sessionStorage.getItem("runTimes"));
    if(planData.cases[r+1].caseNumber){
      if (address.indexOf("?") > 0) {
        window.location.href = address + "&_from=" + planData.cases[r+1].caseNumber;
      } else {
        window.location.href = address + "?_from=" + planData.cases[r+1].caseNumber;
      }
    }
    window.sessionStorage.setItem("runTimes",r+1);
  }
}
function testStart() {
  var test = new TestProject();
  test.init();
}
exports.start = testStart;